package com.vancouver.knows.business.tracker;

import java.util.List;

import com.pangu.task.IResultReceiver;
import com.pangu.task.OperateResult;
import com.pangu.task.mark.ATaskMark;
import com.vancouver.knows.business.BusinessModule;
import com.vancouver.knows.business.Constants;
import com.vancouver.knows.business.bean.CommentInfo;
import com.vancouver.knows.business.task.mark.MyCommentTaskMark;
import com.vancouver.knows.business.task.mark.UserDeleteCommentTaskMark;

/**
 * 删除用户评论
 * 
 * @author chenxunlin01
 * 
 */
public class UserDelCommentTracker extends ABInvokeTracker {

	public UserDelCommentTracker(BusinessModule module, IResultReceiver resultReceiver) {
		super(module, resultReceiver);
	}

	@Override
	protected void handleTaskRefresh(ATaskMark taskMark, OperateResult result) {
	}

	@Override
	public String TAG() {
		return UserDelCommentTracker.class.getSimpleName();
	}

	@Override
	public void handleResult(OperateResult result) {
		UserDeleteCommentTaskMark aTaskMark = (UserDeleteCommentTaskMark) result.getTaskMark();
		String commentId = aTaskMark.getCommentId();

		// 删除对应的评论缓存
		MyCommentTaskMark myCommentTaskMark = module.getTaskMarkPool().getMyCommentTaskMark();
		module.getCacheManager().getMyCommentCache().deleteItemInfoIndexFromCache(myCommentTaskMark, commentId);

		List<CommentInfo> comments = module.getCacheManager().getCommentInfoMap().get(aTaskMark.getPostId());
		if (comments != null) {
			for (CommentInfo commentInfo : comments) {
				if (commentInfo.getId().equals(aTaskMark.getCommentId())) {
					comments.remove(commentInfo);
					break;
				}
			}
		}

		imContext.handleMobEmptyMessage(Constants.BUSINESS_STATUS_DEL_USER_COMMENT);
	}
}
